/**
 * \file Thread_Win32.h
 * \brief Thread definition class
 * \author Edouard ROGE
 * \date 29 august 2012
 */

#ifndef _THREAD_WIN32_
#define _THREAD_WIN32_

#include "Core/Error/Error.h"
#include "Core/Memory/HeapObject.h"

namespace Core
{
	namespace Thread
	{
		/**
		 * \class Thread
		 * \brief Virtual class. Inherit from it to perform computations on another thread
		 */
		class Thread : public Memory::HeapObject
		{
		public:

			/**
			 * \fn Thread();
			 * \brief Default constructor
			 */
			Thread();

			/**
			 * \fn virtual ~Thread();
			 * \brief Destructor
			 */
			virtual ~Thread();

			/**
			 * \fn uint32 GetThreadId() const;
			 * \return the current thread id
			 * \brief get the current thread id
			 */
			uint32 GetThreadId() const;

			/**
			 * \fn virtual void Start();
			 * \brief Start the task
			 */
			virtual void Start();

			/**
			 * \fn virtual void Run()=0;
			 * \brief overload this function. this function is executed on another thread
			 */
			virtual void Run() = 0;

		private:

			/**
			 * \fn static void * RunThread(void * _pContext);
			 * \brief function to start the thread after its register in the ThreadManager
			 */
			static DWORD WINAPI RunThread(void * _pContext);

			/** thread id */
			uint32 m_thread;

			/** parent thread id */
			uint32 m_parentThread;

			/** Windows handle to the thread */
			HANDLE m_handle;

			friend class ThreadManager;

			friend class ThreadLauncher;
		};
	}
}

#endif // _THREAD_WIN32_
